<?php
########################################################################################
# Empresa :     Tecnopac Informatica;                                                  #
# Autor:        Deiverson Pacheco;                                                     #
# Data Criação: 10/12/2010;                                                            #
########################################################################################
session_start();
header("Cache-control: private");
include_once("../../includes/session.php");


//Linha para formatação de caracteres com acentuação
header("Content-Type: text/html; charset=ISO-8859-1",true);


//======================================================================================
//==> Include obrigatórias no script
//======================================================================================
include_once('../../includes/classes/class.TemplatePower.php');
include_once('../../includes/classes/class.Conexao.php');
include_once('../../includes/classes/class.Geral.php');
include_once('../../includes/classes/class.Paginador.php');

//======================================================================================
//==> Inicializar Classes
//======================================================================================
$not  = new Persist;
$data = new getData;
$cor  = new ColorTr;
$util = new Util;
$vld  = new ValidarDados;
$sql  = new SqlInjection;
$Paginacao = new Paginacao(6,3);

//======================================================================================
//==> Instanciar TemplatePower para juntar o PHP + HTML
//======================================================================================
$tpl  = new TemplatePower('../../html/financeiro/titulosr.html');
$tpl->prepare();


//======================================================================================
//==> Recebe variaveis de pesquisa
//======================================================================================
$busca  = @$_GET['busca'];
$filtro = @$_GET['filtro'];
$pagina = @$_GET['pagina'] == '' ? 1 : $_GET['pagina'];

$sql_busca = '';

if($filtro == 'descricao'){
   $sql_busca = " and descricao like '%$busca%' ";
}else{
   $sql_busca = " and parcelas.id_titulo like '%$busca%' ";
}

$cont   = 1;
$not->sql = "select parcelas.id, parcelas.id_titulo, parcelas.valor, parcelas.parcela, parcelas.de, titulos.id_pedido, cadastro.nome_razao, 
parcelas.dt_venc, formas_pagamento.descricao
from parcelas inner join titulos
on parcelas.id_titulo = titulos.id
inner join cadastro
on titulos.id_cliente = cadastro.id
inner join formas_pagamento
on parcelas.form_pag = formas_pagamento.id
where parcelas.ativo = '1' and titulos.tipo = '1' $sql_busca order by parcelas.dt_venc asc";
$tpl->assign('pag',$Paginacao->montaPaginacao($not->sql,'php/financeiro/titulosr.php?busca='.$busca.'&filtro='.$filtro,$pagina));
$not->sql = $Paginacao->montaQuery($not->sql,$pagina);

if($not->ler()>0){
	while($not->ini()){
		$tpl->newBlock('LOOP');
		$tpl->assign('cont',$cont);
		$cont++;
		$tpl->assign('id', $not->id_titulo.' - '.$not->parcela.'/'.$not->de);
		$tpl->assign('pedido', $not->id_pedido);
		$tpl->assign('cliente', $not->nome_razao);
		$tpl->assign('form_pag', $not->descricao);
		$tpl->assign('vencimento', $data->getDataFormatada($not->dt_venc));
		$tpl->assign('valor', number_format($not->valor,2,',','.'));
		$tpl->assign('cor', $cor->altColor());

		//REFERENTE AOS LINKS DOS BOTOES EDITAR E EXCLUIR;
		$tpl->assign('par_id',$not->id);
		
	}
}
$tpl->goToBlock('_ROOT');

//======================================================================================
//==> Enviar página unificada PHP + HTML
//======================================================================================
$tpl->showUnAssigned( false );  // para debug. na hora de publicar, setar para false
$tpl->printToScreen();
?>